{% extends "base.html" %}

{% block content %}
<div class="py-5">
    <div class="container">
        <div class="row">
            <div class="col-12" style="">
                <h2>图书信息</h2>
                <hr class="mb-4">
            </div>
        </div>
        <div class="row">
            <div class="p-3 col-md-8">
                <table class="table table-bordered table-hover table-striped">
                    <tbody>
                        <tr>
                            <th scope="row">编号</th>
                            <td>{{ book.id }}</td>
                        </tr>
                        <tr>
                            <th scope="row">书名</th>
                            <td>{{ book.name }}</td>
                        </tr>
                        <tr>
                            <th scope="row">作者</th>
                            <td>
                                {% for write in book.write_set.all %}
                                {{ write.writer }}
                                {% endfor %}
                            </td>
                        </tr>
                        <tr>
                            <th scope="row">出版社</th>
                            <td>{{ book.publish }}</td>
                        </tr>
                        <tr>
                            <th scope="row">出版时间</th>
                            <td>{{ book.time }}</td>
                        </tr>
                        <tr>
                            <th scope="row">定价</th>
                            <td>{{ book.price }}</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
        <div class="row">
            <div class="col-12 col-md-12">
                <h3>馆藏书籍</h3>
                <hr class="mb-4">
            </div>
        </div>
        {% if book.store_set.all.count == 0 %}
        <div class="row">
            <div class="col-md-12">
                <h4> 没有馆藏 </h4>
            </div>
        </div>
        {% else %}
        <div class="row">
            <div class="col-md-12">
                <div class="col-md-8 p-3">
                    <table class="table table-hover table-striped table-bordered">
                        <thead class="thead-inverse">
                            <tr>
                                <th scope="col">编号</th>
                                <th scope="col">馆藏地点</th>
                                <th scope="col">状态</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for store in book.store_set.all %}
                            <tr>
                                <td>{{ store.id }}</td>
                                <td>{{ store.location }}</td>
                                <td>
                                    {% if store.state == 0 %}
                                    借出
                                    {% elif store.state == 1 %}
                                    在馆
                                    {% else %}
                                    损坏
                                    {% endif %}
                                </td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        {% endif %}
    </div>
</div>
{% endblock %}